<?php
define('IMG_HOST', 'http://static.kimbs.local/img/');
define('JS_HOST', 'http://static.kimbs.local/js/');
define('CSS_HOST', 'http://static.kimbs.local/css/');

define('AUTH_USER', 't');
define('AUTH_PW', 't');

define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'kimbs');

require_once 'db.php';

$lang = include dirname(__FILE__) . '/../locale/zh_CN.php';

function __($s)
{
    global $lang;
    $l = $s;
    if (isset($lang[$s])) {
        $l = $lang[$s];
    }
	echo $l;
}

function k_bottomJs()
{
    //echo 'bottom js here';
}

function k_brower()
{
    $agent = $_SERVER['HTTP_USER_AGENT'];
    if (false !== strpos($agent, 'Firefox')) {
        $brower = 'firefox';
    } elseif (false !== strpos($agent, 'Chrome')) {
        $brower = 'chrome';
    } elseif (false !== strpos($agent, 'Safari')) {
        $brower = 'safari';
    } elseif (false !== strpos($agent, 'Opera')) {
        $brower = 'opera';
    } else {
        $brower = 'ie';
    }
    return $brower;
}

/**
 * check if directory is writeable
 */
function k_dirWriteable($dir)
{
	$writeable = 0;
	if (!is_dir($dir)) {
        return $writeable;
	} else if ($fp = @fopen("$dir/w.log", 'w')) {
        @fclose($fp);
        @unlink("$dir/w.log");
        $writeable = 1;
	}
	return $writeable;
}

/**
 * get random hash string
 */
function k_random($length)
{
    $hash = '';
    $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
    $max = strlen($chars) - 1;
    if (PHP_VERSION < '4.2.0') {
        mt_srand((double)microtime() * 1000000);
    }
    for ($i = 0; $i < $length; $i++) {
        $hash .= $chars[mt_rand(0, $max)];
    }
    return $hash;
}

/**
 * get $_GET,$_POST,$_COOKIE,$_REQUEST
 */
function getgpc($k, $t='GP') {
	$t = strtoupper($t);
	switch($t) {
		case 'GP' : isset($_POST[$k]) ? $var = &$_POST : $var = &$_GET; break;
		case 'G': $var = &$_GET; break;
		case 'P': $var = &$_POST; break;
		case 'C': $var = &$_COOKIE; break;
		case 'R': $var = &$_REQUEST; break;
	}
	return isset($var[$k]) ? $var[$k] : null;
}